package org.bdware.irs.server.tcp;

import org.apache.log4j.Logger;
import org.bdware.irp.irpserver.IrpListenerInfo;
import org.bdware.irp.irpserver.IrpServer;
import org.bdware.irp.irpserver.IrpServerImpl;
import org.bdware.irp.irpserver.IrpServerInfo;
import org.bdware.irs.backend.servicesImpl.BDGrsStorageRocksDBImpl;
import org.bdware.irs.backend.servicesImpl.BDIrsStorageImpl;
import org.bdware.irs.irp.handle.GrsHandlerImpl;
import org.bdware.irs.server.http.GrsHandler;

import java.util.ArrayList;
import java.util.List;

public class GrsServerMain {
    static Logger logger = Logger.getLogger(IrpServerMain.class);
    final static String configFilePath = "default_grs.json";
    static GrsHandlerImpl grsHandler;
    static BDGrsStorageRocksDBImpl store;
    static IrpServerInfo info;
    static{
        logger.info("****init the grs service***");
        store = new BDGrsStorageRocksDBImpl();

        IrpListenerInfo listenerInfo = new IrpListenerInfo(2642, "TCP");
        List<IrpListenerInfo> listenerInfos = new ArrayList<IrpListenerInfo>();
        listenerInfos.add(listenerInfo);
        info = new IrpServerInfo(2642, listenerInfos);
        grsHandler = new GrsHandlerImpl(info, store);
    }

    public static BDGrsStorageRocksDBImpl getStore(){
        return store;
    }

    public static GrsHandlerImpl getGrsHandler() {
        return grsHandler;
    }

    public static void main(String[] args) {

        IrpServer server = IrpServerImpl.createIrpServer(info);
        server.setGrsServerHandler(grsHandler);
        server.start();
    }
}
